package com.example.projectjava.service;


import com.example.projectjava.dao.CategoryDao;
import com.example.projectjava.dao.TrolleyDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class TrolleyService {
    @Autowired
    TrolleyDao trolleyDao;//spring会自动将TrolleyDao注入到此类为(自动为该属性赋值)
    public List<Map<String,Object>> queryAlltrolley(){
        return  trolleyDao.queryAlltrolley();
    }
 //return TrolleyDao.trolleyadd(userName,goodsName,price);


    public  int trolleyadd(String userName,String goodsName,double price,int count){

        return    trolleyDao.trolleyadd(userName,goodsName,price,count);
    }
    public  int trolleyUpdate(String userName,String goodsName,double price,int count){

        return   trolleyDao.trolleyUpdate(userName,goodsName,price,count);//返回了一个整数，用来表示此操作有没有成功
    }
    public int deleteTrolley(String userName,String goodsName) {
        int res = trolleyDao.deleteTrolley(userName,goodsName);
        if (res <= 0) {
            throw new RuntimeException("商品不存在");
        } else {
            return 1;
        }
    }
    public List<Map<String, Object>> querytrolley(String userName){
        return  trolleyDao.querytrolley(userName);}
}

